﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

namespace NKD07.Classes
{
    public abstract class database
    {
        private SqlConnection connection;

        public SqlConnection Connection
        {
            get { return connection; }
            set { connection = value; }
        }

        // open a connection to database
        public void OpenConnection()
        {
            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["BookStoreDBConnectionString"].ConnectionString;
                connection = new SqlConnection(connectionString);
            }
            catch (SqlException ex)
            {
                connection = null;
            }
        }

        // close connection from database
        public void CloseConnection()
        {
            if (connection.State == System.Data.ConnectionState.Open || connection != null)
                connection.Close();
        }
    }
}